<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 卡券基本表模型
 * @package App\Models
 */
class WxCardBase extends Model
{
    use SoftDeletes;
    protected $table = 'wx_card_bases';
    //主键
    protected $primaryKey = 'card_base_id';
    protected $dateFormat = 'Y-m-d H:i:s';
    /**
     * 需要转换成日期的属性
     * @var array
     */
    protected $dates = [

    ];
    /**
     * 应该被转换成原生类型的属性。
     * @var array
     */
    protected $casts = [
        'date_info' => 'array',
        'sku' => 'array',
        'location_id_list' => 'array',
        'center_info' => 'array',
        'custom_info' => 'array',
        'promotion_info' => 'array',
    ];
    /**
     * 卡券高级字段模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function advance()
    {
        return $this->hasOne('App\Models\WxCardAdvance','card_base_id', 'card_base_id');
    }

    /**
     * 卡券扩展字段模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function ext()
    {
        return $this->hasOne('App\Models\WxCardExt','card_base_id', 'card_base_id');
    }
    /**
     * 会员卡模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function member()
    {
        return $this->hasOne('App\Models\WxCardMember','card_base_id', 'card_base_id');
    }

    /**
     * 已领取卡券模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function receive()
    {
        return $this->hasMany('App\Models\WxCardReceive','card_id', 'card_id');
    }

    /**
     * 转赠卡券模型关联
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function transfer()
    {
        return $this->hasMany('App\Models\WxCardTransfer','card_id', 'card_id');
    }
}
